import java.util.Vector;


class P263_39643 {
	static String readLn() {
		String newLine = System.getProperty("line.separator");
		StringBuffer buffer = new StringBuffer();
		int car = -1;
		try {
			car = System.in.read();
			while ((car > 0) && (car != newLine.charAt(0))) {
				buffer.append((char) car);
				car = System.in.read();
			}
			if (car == newLine.charAt(0))
				System.in.skip(newLine.length() - 1);
		} catch (java.io.IOException e) {
			return (null);
		}
		if ((car < 0) && (buffer.length() == 0))
			return (null);
		return (buffer.toString()).trim();
	}

	public static void main(String[] args) {
		
		String line = readLn();
		
		while (line != null && !"0".equals(line)) {
			process(line);
			System.out.println();
			line = readLn();
		}
		
	}

	private static void process(String number) {
		System.out.println("Original number was " + number);
		
		Vector chain = new Vector();
			
			
		
		while (true) {
			
			int ascending = getAscending(number);
			int descending = getDescending(number);
		
			
			
			number = Integer.toString(descending - ascending);
			
			System.out.println(descending + " - " + ascending + " = " + number);
			
			if (chain.contains(number)) break;
			else chain.addElement(number);
		} 
		
		
		System.out.println("Chain length " + (chain.size() + 1));
		
		
	}

	private static int getAscending(String number) {
		char[] array = number.toCharArray();
		
		sortAscending(array);
		
		String s = new String(array);
		
		return Integer.parseInt(s);
	}

	private static int getDescending(String number) {
		char[] array = number.toCharArray();
		
		sortDescending(array);
		
		String s = new String(array);
		
		return Integer.parseInt(s);
	}

	private static void sortAscending(char[] array) {
		
		for (int k = 0; k < array.length; k++) {
			for (int j = k + 1; j < array.length; j++) {
				if (array[k] > array[j]) 
					swap(array, k, j);
			}
		}
		
	}
	
	private static void sortDescending(char[] array) {
		
		for (int k = 0; k < array.length; k++) {
			for (int j = k + 1; j < array.length; j++) {
				if (array[k] < array[j]) 
					swap(array, k, j);
			}
		}
		
	}

	private static void swap(char[] array, int k, int j) {
		char aux = array[k];
		array[k] = array[j];
		array[j] = aux;
	}
	
}
